home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacOS 8 Resources / Developer Tools / Mac OS 8 Interfaces & Libraries / Interfaces / PInterfaces / NumberFormatting.p < prev    next >
Text File  |  1996-05-01  |  13KB  |  290 lines

  1. {
  2.      File:        NumberFormatting.p
  3.  
  4.      Version:    Technology:    8.0
  5.                  Release:    Universal Interfaces 3.0d3 on Copland DR1
  6.  
  7.      Copyright:    © 1984-1996 by Apple Computer, Inc.  All rights reserved.
  8.  
  9.      Bugs?:        If you find a problem with this file, send the file and version
  10.                  information (from above) and the problem description to:
  11.  
  12.                      Internet:    apple.bugs@applelink.apple.com
  13.                      AppleLink:    APPLE.BUGS
  14.  
  15. }
  16. {$IFC UNDEFINED UsingIncludes}
  17. {$SETC UsingIncludes := 0}
  18. {$ENDC}
  19.  
  20. {$IFC NOT UsingIncludes}
  21.  UNIT NumberFormatting;
  22.  INTERFACE
  23. {$ENDC}
  24.  
  25. {$IFC UNDEFINED __NUMBERFORMATTING__}
  26. {$SETC __NUMBERFORMATTING__ := 1}
  27.  
  28. {$I+}
  29. {$SETC NumberFormattingIncludes := UsingIncludes}
  30. {$SETC UsingIncludes := 1}
  31.  
  32. {$IFC UNDEFINED __CONDITIONALMACROS__}
  33. {$I ConditionalMacros.p}
  34. {$ENDC}
  35. {$IFC UNDEFINED __TYPES__}
  36. {$I Types.p}
  37. {$ENDC}
  38. {$IFC FOR_SYSTEM8_PREEMPTIVE }
  39. {$IFC UNDEFINED __TEXTOBJECTS__}
  40. {$I TextObjects.p}
  41. {$ENDC}
  42. {$IFC UNDEFINED __TEXTCOMMON__}
  43. {$I TextCommon.p}
  44. {$ENDC}
  45. {$IFC UNDEFINED __LOCALEOBJECTS__}
  46. {$I LocaleObjects.p}
  47. {$ENDC}
  48. {$IFC UNDEFINED __TEXTPARSER__}
  49. {$I TextParser.p}
  50. {$ENDC}
  51. {$ENDC}
  52. {$IFC FOR_SYSTEM7_AND_SYSTEM8_COOPERATIVE }
  53. {$IFC UNDEFINED __INTLRESOURCES__}
  54. {$I IntlResources.p}
  55. {$ENDC}
  56. {$ENDC}
  57.  
  58. {$PUSH}
  59. {$ALIGN MAC68K}
  60. {$LibExport+}
  61.  
  62. {
  63.  
  64.     Here are the current System 7 routine names and the translations to the older forms.
  65.     Please use the newer forms in all new code and migrate the older names out of existing
  66.     code as maintainance permits.
  67.     
  68.     New Name                    Old Name(s)
  69.     
  70.     ExtendedToString            FormatX2Str
  71.     FormatRecToString            Format2Str
  72.     NumToString                
  73.     StringToExtended            FormatStr2X
  74.     StringToFormatRec            Str2Format
  75.     StringToNum                
  76.  
  77. }
  78. {$IFC FOR_SYSTEM7_AND_SYSTEM8_PREEMPTIVE }
  79.  
  80. TYPE
  81.     NumFormatStringPtr = ^NumFormatString;
  82.     NumFormatString = PACKED RECORD
  83.         fLength:                UInt8;
  84.         fVersion:                UInt8;
  85.         data:                    PACKED ARRAY [0..253] OF CHAR;            {  private data  }
  86.     END;
  87.  
  88.     NumFormatStringRec                    = NumFormatString;
  89.     NumFormatStringRecPtr                 = ^NumFormatStringRec;
  90. {$ENDC}
  91. {$IFC FOR_SYSTEM7_AND_SYSTEM8_COOPERATIVE }
  92.  
  93. TYPE
  94.     FormatStatus                        = INTEGER;
  95.  
  96. CONST
  97.     fVNumber                    = 0;                            {  first version of NumFormatString  }
  98.  
  99.  
  100. TYPE
  101.     FormatClass                            = SInt8;
  102.  
  103. CONST
  104.     fPositive                    = 0;
  105.     fNegative                    = 1;
  106.     fZero                        = 2;
  107.  
  108.  
  109. TYPE
  110.     FormatResultType                    = SInt8;
  111.  
  112. CONST
  113.     fFormatOK                    = 0;
  114.     fBestGuess                    = 1;
  115.     fOutOfSynch                    = 2;
  116.     fSpuriousChars                = 3;
  117.     fMissingDelimiter            = 4;
  118.     fExtraDecimal                = 5;
  119.     fMissingLiteral                = 6;
  120.     fExtraExp                    = 7;
  121.     fFormatOverflow                = 8;
  122.     fFormStrIsNAN                = 9;
  123.     fBadPartsTable                = 10;
  124.     fExtraPercent                = 11;
  125.     fExtraSeparator                = 12;
  126.     fEmptyFormatString            = 13;
  127.  
  128.  
  129. TYPE
  130.     FVectorPtr = ^FVector;
  131.     FVector = RECORD
  132.         start:                    INTEGER;
  133.         length:                    INTEGER;
  134.     END;
  135.  
  136. {  index by [fPositive..fZero]  }
  137.     TripleInt                            = ARRAY [0..2] OF FVector;
  138. {$ENDC}
  139. {$IFC FOR_SYSTEM7_AND_SYSTEM8_PREEMPTIVE }
  140. PROCEDURE StringToNum(theString: Str255; VAR theNum: LONGINT);
  141. PROCEDURE NumToString(theNum: LONGINT; VAR theString: Str255);
  142. {$ENDC}
  143. {$IFC FOR_SYSTEM7_AND_SYSTEM8_COOPERATIVE }
  144. FUNCTION ExtendedToString(VAR x: extended80; {CONST}VAR myCanonical: NumFormatString; {CONST}VAR partsTable: NumberParts; VAR outString: Str255): FormatStatus;
  145.     {$IFC NOT GENERATINGCFM}
  146.     INLINE $2F3C, $8210, $FFE8, $A8B5;
  147.     {$ENDC}
  148. FUNCTION StringToExtended(source: Str255; {CONST}VAR myCanonical: NumFormatString; {CONST}VAR partsTable: NumberParts; VAR x: extended80): FormatStatus;
  149.     {$IFC NOT GENERATINGCFM}
  150.     INLINE $2F3C, $8210, $FFE6, $A8B5;
  151.     {$ENDC}
  152. FUNCTION StringToFormatRec(inString: Str255; {CONST}VAR partsTable: NumberParts; VAR outString: NumFormatString): FormatStatus;
  153.     {$IFC NOT GENERATINGCFM}
  154.     INLINE $2F3C, $820C, $FFEC, $A8B5;
  155.     {$ENDC}
  156. FUNCTION FormatRecToString({CONST}VAR myCanonical: NumFormatString; {CONST}VAR partsTable: NumberParts; VAR outString: Str255; VAR positions: TripleInt): FormatStatus;
  157.     {$IFC NOT GENERATINGCFM}
  158.     INLINE $2F3C, $8210, $FFEA, $A8B5;
  159.     {$ENDC}
  160. {$ENDC}
  161. {$IFC OLDROUTINENAMES }
  162. {$IFC FOR_SYSTEM7_AND_SYSTEM8_DEPRECATED }
  163. {$ENDC}
  164. {  FOR_SYSTEM7_AND_SYSTEM8_DEPRECATED }
  165. {$ENDC}
  166. {  OLDROUTINENAMES }
  167. {$IFC FOR_SYSTEM8_PREEMPTIVE }
  168.  
  169. TYPE
  170.     LocaleNumberFormatterObjectRef        = LocaleObjectRef;
  171.     NumberFormatterOptionBits            = OptionBits;
  172.     NumberFormatterTokenID                = UInt32;
  173.     FIndexVectorPtr = ^FIndexVector;
  174.     FIndexVector = RECORD
  175.         startIndex:                TextObjectIndex;
  176.         endIndex:                TextObjectIndex;
  177.     END;
  178.  
  179. {  index by [fPositive..fZero]  }
  180.     TripleIndex                            = ARRAY [0..2] OF FIndexVector;
  181.  
  182. CONST
  183.                                                                 { NumberFormatterOptionBits }
  184.     kDontUseThousandSeparatorBit = 0;
  185.     kIsScientificFormatBit        = 1;
  186.     kIsPercentageFormatBit        = 2;
  187.     kIsCurrencyFormatBit        = 3;
  188.     kIsFractionCurrencyFormatBit = 4;
  189.     kIsLongFormCurrencyFormatBit = 5;
  190.     kOmitDecimalPointInCurrencyFormatBit = 6;
  191.     kUseAsciiDigitBit            = 7;
  192.     kUseNegativePosfixPrefixBit    = 8;
  193.  
  194.                                                                 { NumberFormatterOptionBits }
  195.     kStandardFormatMask            = 0;
  196.     kDontUseThousandSeparatorMask = $00000001;
  197.     kIsScientificFormatMask        = $00000002;
  198.     kIsPercentageFormatMask        = $00000004;
  199.     kIsCurrencyFormatMask        = $00000008;
  200.     kIsFractionCurrencyFormatMask = $00000010;
  201.     kIsLongFormCurrencyFormatMask = $00000020;
  202.     kOmitDecimalPointInCurrencyFormatMask = $00000040;
  203.     kUseAsciiDigitMask            = $00000080;
  204.     kUseNegativePosfixPrefixMask = $00000100;
  205.  
  206. FUNCTION GetNumberFormatterObjectFromRef(locale: LocaleRef; VAR numberFormatterObject: LocaleNumberFormatterObjectRef): OSStatus; C;
  207. FUNCTION GetNumberFormatterObjectFromID(localeID: LocaleIdentifier; VAR numberFormatterObject: LocaleNumberFormatterObjectRef): OSStatus; C;
  208. FUNCTION GetCurrentNumberFormatterObject(VAR numberFormatterObject: LocaleNumberFormatterObjectRef): OSStatus; C;
  209. FUNCTION GetNumberFormatterObjectInfo(numberFormatterObject: LocaleNumberFormatterObjectRef; VAR theEncoding: TextEncoding; VAR theLocaleIdentifier: LocaleIdentifier): OSStatus; C;
  210. FUNCTION ConvertUInt32ToTextObject(theUInt32: UInt32; numberFormatterObject: LocaleNumberFormatterObjectRef; options: NumberFormatterOptionBits; theTextObject: TextObject; startReplaceIndex: TextObjectIndex; endReplaceIndex: TextObjectIndex): OSStatus; C;
  211. FUNCTION ConvertSInt32ToTextObject(theSInt32: SInt32; numberFormatterObject: LocaleNumberFormatterObjectRef; options: NumberFormatterOptionBits; theTextObject: TextObject; startReplaceIndex: TextObjectIndex; endReplaceIndex: TextObjectIndex): OSStatus; C;
  212. FUNCTION ConvertUInt64ToTextObject(theUInt64: UInt64; numberFormatterObject: LocaleNumberFormatterObjectRef; options: NumberFormatterOptionBits; theTextObject: TextObject; startReplaceIndex: TextObjectIndex; endReplaceIndex: TextObjectIndex): OSStatus; C;
  213. FUNCTION ConvertSInt64ToTextObject(theSInt64: SInt64; numberFormatterObject: LocaleNumberFormatterObjectRef; options: NumberFormatterOptionBits; theTextObject: TextObject; startReplaceIndex: TextObjectIndex; endReplaceIndex: TextObjectIndex): OSStatus; C;
  214. FUNCTION ConvertDoubleToTextObject(theDouble: Double; numberFormatterObject: LocaleNumberFormatterObjectRef; options: NumberFormatterOptionBits; precision: SInt8; theTextObj: TextObject; startReplaceIndex: TextObjectIndex; endReplaceIndex: TextObjectIndex): OSStatus; C;
  215. FUNCTION ConvertTextObjectToUInt32(textObject: ConstTextObject; numberFormatterObject: LocaleNumberFormatterObjectRef; options: NumberFormatterOptionBits; startIndex: TextObjectIndex; endIndex: TextObjectIndex; VAR theUInt32: UInt32): OSStatus; C;
  216. FUNCTION ConvertTextObjectToSInt32(textObject: ConstTextObject; numberFormatterObject: LocaleNumberFormatterObjectRef; options: NumberFormatterOptionBits; startIndex: TextObjectIndex; endIndex: TextObjectIndex; VAR theSInt32: SInt32): OSStatus; C;
  217. FUNCTION ConvertTextObjectToUInt64(textObject: ConstTextObject; numberFormatterObject: LocaleNumberFormatterObjectRef; options: NumberFormatterOptionBits; startIndex: TextObjectIndex; endIndex: TextObjectIndex; VAR theUInt64: UInt64): OSStatus; C;
  218. FUNCTION ConvertTextObjectToSInt64(textObject: ConstTextObject; numberFormatterObject: LocaleNumberFormatterObjectRef; options: NumberFormatterOptionBits; startIndex: TextObjectIndex; endIndex: TextObjectIndex; VAR theSInt64: SInt64): OSStatus; C;
  219. FUNCTION ConvertTextObjectToDouble(textObject: ConstTextObject; localeObjectRef: LocaleNumberFormatterObjectRef; startIndex: TextObjectIndex; endIndex: TextObjectIndex; VAR theDouble: Double): OSStatus; C;
  220. FUNCTION FormattedTextObjectToDouble(textObject: ConstTextObject; ref: LocaleNumberFormatterObjectRef; startIndex: TextObjectIndex; endIndex: TextObjectIndex; {CONST}VAR myCanonical: NumFormatString; {CONST}VAR num: Double): OSStatus; C;
  221. FUNCTION DoubleToFormattedTextObject(VAR num: Double; ref: LocaleNumberFormatterObjectRef; {CONST}VAR myCanonical: NumFormatString; outTextObject: TextObject): OSStatus; C;
  222. FUNCTION TextObjectToFormatRec(textObject: ConstTextObject; ref: LocaleNumberFormatterObjectRef; startIndex: TextObjectIndex; endIndex: TextObjectIndex; VAR outString: NumFormatString): OSStatus; C;
  223. FUNCTION FormatRecToTextObject({CONST}VAR myCanonical: NumFormatString; ref: LocaleNumberFormatterObjectRef; outTextObject: TextObject; VAR positions: TripleIndex): OSStatus; C;
  224.  
  225. CONST
  226.                                                                 {  NumberFormatterTokenID }
  227.     kNumFmtCharLeftQuote        = 0;                            { (begin literal) }
  228.     kNumFmtCharRightQuote        = 1;                            { (end literal) }
  229.     kNumFmtCharLeadPlacer        = 2;                            {  (`^' in U.S) }
  230.     kNumFmtCharLeader            = 3;                            { (non-breakable space in U.S) }
  231.     kNumFmtCharNonLeader        = 4;                            { (# sign in U.S) }
  232.     kNumFmtCharZeroLead            = 5;                            { (digit `0' in U.S) }
  233.     kNumFmtCharCurrencyPlacer    = 6;                            {  (`$' in U.S) }
  234.     kNumFmtCharPercent            = 7;                            {  (`%')  }
  235.     kNumFmtCharPlusSign            = 8;                            {  (`+') }
  236.     kNumFmtCharMinusSign        = 9;                            {  (`-')  }
  237.     kNumFmtCharThousandSep        = 10;                            {  (`,')  }
  238.     kNumFmtCharFormatSeparator    = 11;                            {  (`;')  }
  239.     kNumFmtCharEscape            = 12;                            {   (`\')  }
  240.     kNumFmtCharDecPoint            = 13;                            {  (`.')  }
  241.     kNumFmtTextpePlus            = 14;                            {  (`E+')  }
  242.     kNumFmtTextpeMinus            = 15;                            {  (`E-')  }
  243.     kNumFmtTextMinusPlus        = 16;                            {  (`E')  }
  244.     kNumFmtTextFirstRangeCurrencyForm = 17;                        {  (`Dollar')  }
  245.     kNumFmtTextSecondRangeCurrencyForm = 18;                    {  (`Dollar(s)')  }
  246.     kNumFmtTextPluralCurrency    = 19;                            {  (`Dollar(s)')  }
  247.     kNumFmtTextfractionCurrency    = 20;                            {  (`cents))  }
  248.     kNumFmtTextCurrencyAbbreviated = 21;                        {  (`$')  }
  249.     kNumFmtTextfractionCurrencyAbbreviated = 22;                {  (`¢')  }
  250.     kNumFmtTextNegativePrefix    = 23;                            {  (`(`)  }
  251.     kNumFmtTextNegativePostfix    = 24;                            {  (`)')  }
  252.  
  253.  
  254. TYPE
  255.     CurrencyPosition                    = UInt32;
  256.  
  257. CONST
  258.                                                                 { CurrencyPosition }
  259.     kAtTheBeginning                = 0;
  260.     kAtDecimalPointPosition        = 1;
  261.     kAtTheEnd                    = 2;
  262.  
  263. FUNCTION CreateCustomNumberFormatLocaleObject(numberFormatterObject: LocaleNumberFormatterObjectRef; VAR customNumberFormatterObject: LocaleNumberFormatterObjectRef): OSStatus; C;
  264. FUNCTION DeleteCustomNumberFormatLocaleObject(customNumberFormatterObject: LocaleNumberFormatterObjectRef): OSStatus; C;
  265. FUNCTION SetNumFmtTokenToParserToken(customNumberFormatterObject: LocaleNumberFormatterObjectRef; tokenID: NumberFormatterTokenID; theToken: BasicToken): OSStatus; C;
  266. FUNCTION GetParserTokenFromNumFmtToken(customNumberFormatterObject: LocaleNumberFormatterObjectRef; tokenID: NumberFormatterTokenID; VAR theToken: BasicToken): OSStatus; C;
  267. FUNCTION GetNumberFormatterTextFromToken(customNumberFormatterObject: LocaleNumberFormatterObjectRef; tokenID: NumberFormatterTokenID; theTextObject: TextObject): OSStatus; C;
  268. FUNCTION SetNumFmtTokenToText(customNumberFormatterObject: LocaleNumberFormatterObjectRef; tokenID: NumberFormatterTokenID; theTextObject: ConstTextObject): OSStatus; C;
  269. FUNCTION GetLocaleLongCurrencyPosition(customNumberFormatterObject: LocaleNumberFormatterObjectRef; VAR position: CurrencyPosition): OSStatus; C;
  270. FUNCTION SetLocaleLongCurrencyPosition(customNumberFormatterObject: LocaleNumberFormatterObjectRef; position: CurrencyPosition): OSStatus; C;
  271. FUNCTION GetLocaleAbbrevCurrencyPosition(customNumberFormatterObject: LocaleNumberFormatterObjectRef; VAR position: CurrencyPosition): OSStatus; C;
  272. FUNCTION SetLocaleAbbrevCurrencyPosition(customNumberFormatterObject: LocaleNumberFormatterObjectRef; position: CurrencyPosition): OSStatus; C;
  273. FUNCTION GetLocaleFirstRangeCurrency(customNumberFormatterObject: LocaleNumberFormatterObjectRef; VAR maxValueInRange: UInt32): OSStatus; C;
  274. FUNCTION SetLocaleFirstRangeCurrency(customNumberFormatterObject: LocaleNumberFormatterObjectRef; maxValueInRange: UInt32): OSStatus; C;
  275. FUNCTION GetLocaleSecondRangeCurrency(customNumberFormatterObject: LocaleNumberFormatterObjectRef; VAR maxValueInRange: UInt32): OSStatus; C;
  276. FUNCTION SetLocaleSecondRangeCurrency(customNumberFormatterObject: LocaleNumberFormatterObjectRef; maxValueInRange: UInt32): OSStatus; C;
  277. FUNCTION GetLocaleDigitText(customNumberFormatterObject: LocaleNumberFormatterObjectRef; theDigit: ByteParameter; theTextObject: TextObject): OSStatus; C;
  278. FUNCTION SetLocaleDigitText(customNumberFormatterObject: LocaleNumberFormatterObjectRef; theDigit: ByteParameter; theTextObject: TextObject): OSStatus; C;
  279. {$ENDC}
  280. {$ALIGN RESET}
  281. {$POP}
  282.  
  283. {$SETC UsingIncludes := NumberFormattingIncludes}
  284.  
  285. {$ENDC} {__NUMBERFORMATTING__}
  286.  
  287. {$IFC NOT UsingIncludes}
  288.  END.
  289. {$ENDC}
  290.